
*********************************************************************************;

/* 			This file produce Summary statistics reported in Table 1			*/

*********************************************************************************;


libname rep "C:\Users\~";

data data_t1; set rep.mydata; run;


*** Panel A: Summary statistics ***;

proc means data = data_t1 N mean t std q1 median q3 ;
var syy hfflow active passive mktrf amihud tover hml smb; run;

*** Panel B: autocorrelation: decomposed variables **;

option missing = " ";
%macro print;
data N; set N; Estimate = nValue1; if Label1 = "Used"; run;
data Nobs; set N; Parameter = "N"; keep EstType Parameter Estimate; run;
data r2; set fit; Parameter = "RSQ"; keep EstType Parameter RSquare; rename RSquare = Estimate;  run;
data adjr2; set fit; Parameter = "AdjRSQ"; keep EstType Parameter AdjRsq; rename AdjRSq = Estimate;  run;
data final; set parest Nobs r2 adjr2; drop EstType StdErr Probt DF; run;
data final&i; set final; rename Estimate = &yvar tValue = t_&i; run;
proc print data = final&i noobs; run;
%mend;

%let var1 = syy_low; 
%let var2 = syy_high;
%let var3 = hfflow_low;
%let var4 = hfflow_high;
%let var5 = active_low; 
%let var6 = active_high;

%macro auto;

%do i=1 %to 6;
%let yvar = &&var&i;
%put &yvar;

proc expand data = data_t1 out = autoreg method = none; id date;
convert &yvar = lag1 / transformout = (lag 1);
run;

ods output "Nonlinear GMM Summary of Residual Errors" = fit;
ods output "Nonlinear GMM Parameter Estimates" = parest;
ods output "Estimation Summary Statistics" = N;
proc model data=autoreg plot =none;
endo &yvar; exog lag1;
instruments _exog_; parms b0 b1;
&yvar=b0 +b1*lag1;
fit &yvar / gmm kernel=(bart,13,0) vardef=n;
run; quit; 
%print;
%end;

data merged1; merge final1 final2 final3 final4 final5 final6 ; run;
proc print noobs; run;
%mend;

%auto;

** Panel B: autocorrelations: filtered variables: ma and changes ***;

%let var1 = syy_ma; 
%let var2 = syy_chg;
%let var3 = hfflow_ma;
%let var4 = hfflow_chg;
%let var5 = active_ma; 
%let var6 = active_chg;

%auto;

/**** Panel C: Variance decomposition: mean and std of decomposed variables: 
/*				These are also needed to calculate Tables 4&5. 				*/

proc means data = data_t1 var ;
var syy syy_low syy_high hfflow hfflow_low hfflow_high active active_low active_high ; run;

proc means data = filtered var;
var syy syy_ma syy_chg hfflow hfflow_ma hfflow_chg active active_ma active_chg; run;

*** Panel D: correlations between decomposed and filtered variables **;

proc corr data = data_t1;
var syy_low syy_ma hfflow_low hfflow_ma active_low active_ma ; run;

proc corr data = data_t1;
var syy_high syy_chg hfflow_high hfflow_chg active_high active_chg ; run;

